<template>
    <section class="embroidery-freedom">
        <div class="embroidery-freedom-container" :style="{ '--describe-rate': beforeRate }">
            <div class="embroidery-freedom-describe">
                <h2>Embroider Wherever You Want </h2>
                <p>
                    Personalize your clothing with the freedom to <strong>place designs exactly as</strong> <br />
                    <em>you wish</em>. You can combine multiple embroidery designs, select <br />
                    different sizes, and adjust positions to wherever you want. Make your <br />
                    creativity shine brighter than ever.
                </p>
                <p>
                    Personalize your clothing with the freedom to <strong>place designs exactly as you wish</strong>.
                    You can combine multiple embroidery designs, select
                    different sizes, and adjust positions to wherever you want. Make your
                    creativity shine brighter than ever.
                </p>
            </div>
            <div class="embroidery-freedom-preview">
                <figure>
                    <img :src="$getImageWebPByUrl('https://img.podpartner.com/static/images-20240628/emb-freedom-1.png')"
                        alt="embroidery-preview">
                </figure>
                <figure>
                    <img :src="$getImageWebPByUrl('https://img.podpartner.com/static/images-20240628/emb-freedom-2.png')"
                        alt="embroidery-preview">
                </figure>
                <figure>
                    <img :src="$getImageWebPByUrl('https://img.podpartner.com/static/images-20240628/emb-freedom-3.png')"
                        alt="embroidery-preview">
                </figure>
            </div>
        </div>
    </section>
</template>
<script>

export default {
    props: {
        screen_height: {
            type: Number,
            default: 0
        },
        cur_scroll: {
            type: Number,
            default: 0
        },
        scroll: {
            type: Number,
            default: 0
        },
        rate: {
            type: Number,
            default: 0
        },
        range: {
            type: Number,
            default: 0
        },
    },
    computed: {
        // 需要一个提前半屏进入
        beforeRate () {
            const before_scroll = Math.max((this.cur_scroll - this.screen_height) + this.screen_height * 0.5, 0); // 触发阈值的滚动值
            const rate = this.$clamp(0, before_scroll / (this.range + this.screen_height * 0.5), 1)
            return rate
        },
    },
    data () {
        return {}
    },
    methods: {}
}
</script>
<style scoped lang="scss">
// 1606 824 720 1606 62
// 1445 741 648 56
.embroidery-freedom {
    --scale: 1;
    width: 100%;
    margin: 0 auto;
    height: calc(var(--screen-height) * 4);

    .embroidery-freedom-container {
        position: fixed;
        bottom: 0;
        left: 50%;
        display: flex;
        flex-direction: row;
        align-items: center;
        width: calc(1606px * var(--scale));
        height: var(--screen-height);
        transform: translate3d(-50%, 0, 0);

        .embroidery-freedom-describe {
            @keyframes text-scroll {
                0% {
                    transform: translate3d(0, 100%, 0) scale(var(--scale));
                }

                100% {
                    transform: translate3d(0, calc(0px - var(--screen-height)), 0) scale(var(--scale));
                }
            }

            position: absolute;
            left: 0;
            bottom: 0;
            transform: translate3d(0, 100%, 0) scale(var(--scale));
            transform-origin: top left;

            animation: text-scroll 0s linear forwards;
            animation-iteration-count: var(--describe-rate);

            h2 {
                width: 100%;
                font-family: Roboto-Medium, Roboto;
                font-weight: 500;
                font-size: 60px;
                color: #000000;
                background: linear-gradient(135deg, #E53BAC 0%, #EDB002 100%);
                -webkit-background-clip: text;
                -webkit-text-fill-color: transparent;
                margin-bottom: 32px;
            }

            p {
                width: 100%;
                font-family: Roboto-Regular, Roboto;
                font-weight: 400;
                font-size: 26px;
                color: #000000;
                line-height: 48px;

                strong {
                    background: linear-gradient(135deg, #E53BAC 0%, #EDB002 100%);
                    -webkit-background-clip: text;
                    -webkit-text-fill-color: transparent;
                }

                em {
                    font-weight: bold;
                    background: linear-gradient(135deg, #E53BAC 0%, #EDB002 100%);
                    -webkit-background-clip: text;
                    -webkit-text-fill-color: transparent;
                }

                &:last-child {
                    display: none
                }
            }
        }

        .embroidery-freedom-preview {
            --min-width: calc(320px * var(--scale));
            --min-height: calc(164px * var(--scale));
            --max-width: calc(720px * var(--scale));
            --max-height: calc(466px * var(--scale));
            position: absolute;
            bottom: 0;
            right: 0;
            width: var(--max-width);
            height: var(--min-height);
            display: flex;
            align-items: center;
            justify-content: center;

            @keyframes preview-trans-start {
                0% {
                    transform: translate3d(0, 100%, 0);
                    width: var(--min-width);
                    height: var(--min-height);
                    opacity: 0;
                    box-shadow: none;
                }

                25% {
                    // opacity: 1;
                }

                34% {
                    // width: var(--min-width);
                    // height: var(--min-height);
                }


                40% {
                    opacity: 1;
                    box-shadow: none;
                }

                45% {
                    width: var(--max-width);
                    height: var(--max-height);
                }

                50% {
                    box-shadow: 0px 0px 70px 0px rgba(0, 0, 0, 0.33);
                }

                55% {
                    width: var(--max-width);
                    height: var(--max-height);
                }

                60% {
                    opacity: 1;
                    box-shadow: none;
                }


                66% {
                    width: var(--min-width);
                    height: var(--min-height);
                }

                75% {
                    opacity: 0;
                }

                100% {
                    opacity: 0;
                    transform: translate3d(0, calc(0px - var(--screen-height)), 0);
                    width: var(--min-width);
                    height: var(--min-height);
                    box-shadow: none;
                }
            }


            @keyframes preview-trans {
                0% {
                    z-index: 0;
                    transform: translate3d(0, 100%, 0);
                    width: var(--min-width);
                    height: var(--min-height);
                    opacity: 0;
                    box-shadow: none;
                }


                25% {
                    opacity: 0;
                }

                34% {
                    width: var(--min-width);
                    height: var(--min-height);
                }

                39% {
                    z-index: 0;
                }

                40% {
                    z-index: 2;
                    opacity: 1;
                    box-shadow: none;
                }

                45% {
                    width: var(--max-width);
                    height: var(--max-height);
                }

                50% {
                    box-shadow: 0px 0px 70px 0px rgba(0, 0, 0, 0.33);
                }

                55% {
                    width: var(--max-width);
                    height: var(--max-height);
                }

                60% {
                    z-index: 2;
                    opacity: 1;
                    box-shadow: none;
                }

                61% {
                    z-index: 0;
                }

                66% {
                    width: var(--min-width);
                    height: var(--min-height);
                }

                75% {
                    opacity: 0;
                }

                100% {
                    opacity: 0;
                    transform: translate3d(0, calc(0px - var(--screen-height)), 0);
                    width: var(--min-width);
                    height: var(--min-height);
                    box-shadow: none;
                }
            }

            @keyframes preview-trans-end {
                0% {
                    transform: translate3d(0, 100%, 0);
                    width: var(--min-width);
                    height: var(--min-height);
                    opacity: 0;
                    box-shadow: none;
                }

                25% {
                    opacity: 0;
                }

                34% {
                    width: var(--min-width);
                    height: var(--min-height);
                }


                40% {
                    opacity: 1;
                    box-shadow: none;
                }

                45% {
                    width: var(--max-width);
                    height: var(--max-height);
                }

                50% {
                    box-shadow: 0px 0px 70px 0px rgba(0, 0, 0, 0.25);
                }

                55% {
                    width: var(--max-width);
                    height: var(--max-height);
                }

                60% {
                    opacity: 1;
                }


                66% {
                    // width: var(--min-width);
                    // height: var(--min-height);
                }

                75% {
                    opacity: 1;
                    // width: var(--min-width);
                    // height: var(--min-height);
                }

                100% {
                    opacity: 1;
                    transform: translate3d(0, calc(0px - var(--screen-height)), 0);
                    // width: var(--min-width);
                    // height: var(--min-height);
                    box-shadow: none;
                    width: var(--max-width);
                    height: var(--max-height);
                }
            }

            figure {
                position: absolute;
                bottom: 0;
                width: var(--min-width);
                height: var(--min-height);
                background: #D3D2CF;
                display: flex;
                align-items: center;
                justify-content: center;
                border-radius: 10px;
                overflow: hidden;
                transform: translate3d(0, 100%, 0);
                animation: preview-trans 0s linear forwards;

                img {
                    height: 90%;
                }

                &:nth-child(1) {
                    z-index: 1;
                    background: #F5F7EC;
                    animation: preview-trans-start 0s linear forwards;
                    animation-iteration-count: clamp(0,
                            calc(var(--describe-rate) / 0.7),
                            1);
                }

                &:nth-child(2) {
                    background: #E8F0F0;
                    z-index: 0;
                    animation-iteration-count: clamp(0,
                            calc((var(--describe-rate) - 0.15) / 0.7),
                            1);
                }

                &:nth-child(3) {
                    z-index: 1;
                    background: #F7EEEE;
                    animation: preview-trans-end 0s linear forwards;
                    animation-iteration-count: clamp(0,
                            calc((var(--describe-rate) - 0.3) / 0.7),
                            1);
                }
            }
        }
    }



}

.embroidery-freedom.animation-none {
    --scale: 1;
    width: 100%;
    margin: 0 auto;
    height: auto;

    .embroidery-freedom-container {
        --describe-rate: 0 !important;
        position: relative;
        bottom: auto;
        left: auto;
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        height: auto;
        transform: none;

        .embroidery-freedom-describe {
            padding: 48px 14px;
            position: static;
            left: auto;
            bottom: auto;
            transform: none;
            animation: none;

            h2 {
                width: 100%;
                font-size: 24px;
                line-height: 28px;
                margin-bottom: 14px;
            }

            p {
                width: 100%;
                font-size: 16px;
                line-height: 24px;
                display: none;

                &:last-child {
                    display: block;
                }
            }
        }

        .embroidery-freedom-preview {
            margin-bottom: 38px;
            box-sizing: border-box;
            padding: 0 14px;
            position: static;
            bottom: auto;
            right: auto;
            width: 100%;
            height: auto;
            flex-direction: column;

            figure {
                padding: 10px 0;
                position: static;
                bottom: auto;
                width: 100%;
                height: auto;
                transform: none;
                animation: none;
                margin-bottom: 10px;

                img {
                    width: 50%;
                    height: auto;
                }
            }
        }
    }




}

@media screen and (max-width: 1660px) {
    .embroidery-freedom {
        --scale: 0.8;
    }
}

@media screen and (max-width: 1400px) {
    .embroidery-freedom {
        --scale: 0.7;
    }
}

@media screen and (max-width: 1200px) {
    .embroidery-freedom {
        --scale: 0.56;
    }
}
</style>